local canmeng = fk.CreateSkill{
    name = "ym1__canmeng",
}
Fk:loadTranslationTable{
    ["ym1__canmeng"] = "残梦",
    ["ym1__huiheskill"] = "<b>回合技</b>：即“每回合限一次”的简称，指“于每个回合中限发动一次”。<br>为标识技能发动频率的词语，不属于技能标签。",
    [":ym1__canmeng"] = "<a href='ym1__huiheskill'>回合技</a>，你可以视为使用一张【无懈可击】。结算前，你将一张牌置为底牌；结算中，你的牌失效；结算后，你须弃置一张牌或重铸两张牌并对两名本回合失去过牌的角色造成1点<font color='#b97eb4'>雷电伤害</font>。",
    ["#ym1__canmeng"] = "残梦：将一张牌置为【无懈可击】的底牌",
    ["@@ym1__canmeng"] = "残梦 卡牌失效",
    ["#ym1__canmeng_effect"] = "残梦",
    ["ym1__canmeng_active"] = "残梦",
    ["#ym1__canmeng_active"] = "残梦：弃置一张牌，或重铸两张牌并对两名本回合失去过牌的角色造成1点雷电伤害",
    ["#ym1__canmeng1"] = "弃牌",
    ["#ym1__canmeng2"] = "重铸",

    ["$ym1__canmeng1"] = "我为逝者哀哭……",
    ["$ym1__canmeng2"] = "暮雨，终将落下。",
    ["$ym1__canmeng3"] = "流淌吧…过往的刀光。",
    ["$ym1__canmeng4"] = "暴雨将至。",
}
canmeng:addEffect("viewas",{
    mute = true,
    anim_type = "control",
    pattern = "nullification",
    prompt = "#ym1__canmeng",
    card_filter = function(self, player, to_select, selected)
        return #selected == 0
    end,
    view_as = function(self, player, cards)
        if #cards ~= 1 and #Self:getCardIds({Player.Hand, Player.Equip}) > 0 then return end
        local card = Fk:cloneCard("nullification")
        card.skillName = canmeng.name
        if #cards ~= 0 then card:addSubcard(cards[1]) end
        return card
    end,
    enabled_at_response = function (self, player, response)
        return not response and player:usedSkillTimes(canmeng.name, Player.HistoryTurn) == 0
    end,
})
canmeng:addEffect("prohibit",{
    prohibit_use = function(self, player, card)
        return player:getMark("@@ym1__canmeng") ~= 0
    end,
    prohibit_response = function(self, player, card)
        return player:getMark("@@ym1__canmeng") ~= 0
    end,
    prohibit_discard = function (self, player, card)
        return player:getMark("@@ym1__canmeng") ~= 0
    end
})
canmeng:addEffect(fk.PreCardUse,{
    can_refresh = function(self, event, target, player, data)
        return target == player and data.card.skillName == "ym1__canmeng"
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player,"ym1__canmeng","control")
        player:broadcastSkillInvoke("ym1__canmeng",math.random(1,2))
        room:setPlayerMark(player, "@@ym1__canmeng", 1)
        room.logic:getCurrentEvent():addCleaner(function ()
            room:setPlayerMark(player, "@@ym1__canmeng", 0)
        end)
    end,
})
canmeng:addEffect(fk.CardUseFinished,{
    can_refresh = function(self, event, target, player, data)
        return target == player and data.card.skillName == "ym1__canmeng" and not player:isNude()
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
            for _, move in ipairs(e.data) do
              if move.from then
                for _, info in ipairs(move.moveInfo) do
                  if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                    room:setPlayerMark(room:getPlayerById(move.from.id), "_ym1__canmeng-phase", 1)
                  end
                end
              end
            end
        end, Player.HistoryTurn)
        --if table.contains({"ym1__huangquan","ym1__huangquan2"},player.general) then
            if player:getMark("#ym1__huangquan_showGeneral") == 0 then
                room:setPlayerMark(player, "#ym1__huangquan_showGeneral", player.general)
            end
            player.general = "ym1__huangquan3"
            room:broadcastProperty(player, "general")
        --end
        local _,dat = player.room:askToUseActiveSkill(player, {
            skill_name = "ym1__canmeng_active",
            prompt = "#ym1__canmeng_active",
            cancelable = false,
        })
        if dat then
            if #dat.cards==1 then
                if player:getMark("#ym1__huangquan_showGeneral") ~= 0 then
                    player.general = player:getMark("#ym1__huangquan_showGeneral")
                    room:broadcastProperty(player, "general")
                end
                room:throwCard(dat.cards, canmeng.name, player, player)
            else
                player:broadcastSkillInvoke("ym1__canmeng",math.random(3,4))
                room:sortByAction(dat.targets)
                room:recastCard(dat.cards, player, canmeng.name)
                for _, pid in ipairs(dat.targets) do
                    local to = room:getPlayerById(pid.id)
                    if not to.dead then
                        room:damage{
                            from = player,
                            to = to,
                            damage = 1,
                            damageType = fk.ThunderDamage,
                            skillName = canmeng.name,
                        }
                    end
                end
                if player:getMark("#ym1__huangquan_showGeneral") ~= 0 then
                    player.general = player:getMark("#ym1__huangquan_showGeneral")
                    room:broadcastProperty(player, "general")
                end
            end
        end
        if player:getMark("#ym1__huangquan_showGeneral") ~= 0 then
            player.general = player:getMark("#ym1__huangquan_showGeneral")
            room:broadcastProperty(player, "general")
        end
    end,
})
return canmeng